home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / label.aqm / label.asm
Encoding:
Assembly Source File  |  1984-10-16  |  11.4 KB  |  250 lines

  1.           name     labl
  2.           page     78,132
  3.           title    'LABEL - display or change volume label'
  4. ;
  5. ;LABEL - display or chnage volume label
  6. ;
  7. ;copyright  1984 by Ray Duncan
  8. ;  May be freely copied for noncommercial use.
  9. cr        equ      0dh            ; ASCII carriage return
  10. lf        equ      0ah            ; ASCII line feed
  11. eom       equ      '$'            ; end of message flag
  12.  
  13.                                   ; Program Prefix Segment
  14. command   equ      80h            ; command line buffer
  15. default_fcb equ    05ch           ; default file control block
  16.  
  17. rd_only   equ      01h            ; file attributes
  18. hidden    equ      02h
  19. system    equ      04h
  20. volume    equ      08h
  21. subdir    equ      10h
  22. archive   equ      20h
  23.  
  24. cseg      segment  para public 'CODE'
  25.           assume   cs:cseg,ds:data,es:data,ss:stack
  26. labl      proc     far            ; entry point from PC-DOS
  27.  
  28.           push     ds             ; save DS:0000 for final return
  29.           xor      ax,ax          ;     to PC-DOS
  30.           push     ax
  31.           mov      ah,48          ; make sure this is DOS
  32.           int      21h            ; version 2.0 or greater
  33.           cmp      al,2
  34.           jae      labl1          ; version is ok jump
  35.           mov      ax,data
  36.           mov      ds,ax
  37.           mov      dx,offset msg6 ; version is too low
  38.           mov      ah,9           ; print error msg and
  39.           int      21h            ; exit
  40.           ret
  41. labl1:    mov      ax,data        ; make our data sement addressable
  42.           mov      es,ax          ; via the ES register
  43.           call     vol_name       ; get name for new volume label
  44.                                   ; if any was given by user
  45.           mov      ax,es          ; now set DS=ES for remainder
  46.           mov      ds,ax          ; of the program
  47.           call     show_label     ; display the current volume label
  48.                                   ; on the selected diskette
  49.                                   ; Subroutine returns:
  50.                                   ;   AX = 0 - no label on diskette
  51.                                   ;   AX = 1 - label does exist
  52.                                   ; was new label supplied by user
  53.           cmp      byte ptr fcb+1,' '
  54.           jne      labl2          ; yes, change/add this volume label
  55.           ret                     ; no, exit to PC-DOS
  56.  
  57. labl2:                            ; new name supplied by user
  58.           or       ax,ax          ; was previous label present?
  59.                                   ; (flag in AX from SHOW_LABEL)e label
  60.           jz       labl3          ; no - jump
  61.           mov      cx,11          ; yes - change it
  62.           mov      di,offset buffer+24
  63.           mov      si,offset fcb+1 ; set up new name starting at
  64.           rep movsb                ; 6 bytes after old name
  65.           mov      dx,offset buffer
  66.           mov      ah,23          ; request alteration of volume name
  67.           int      21h            ; by PC-DOS function 23 - RENAME
  68.           jmp      labl4          ; go check if function was successful,
  69.                                   ; if it was display new volume name
  70.  
  71. labl3:                            ; come here to add new label, if
  72.                                   ; diskette previously had no label
  73.           mov      dx,offset xfcb ; DX = addr of extended fcb
  74.                                   ; containing "volume" attribute byte
  75.           mov      ah,22          ; use PC-DOS function 22 to create
  76.           int      21h            ; a new directory entry,
  77. labl4:    cmp      al,0ffh        ; was function successful?
  78.           jne      labl5          ; yes, jump to display new name,
  79.           mov      dx,offset msg2 ; no, print error message
  80.           mov      ah,9           ; and exit
  81.           int      21h
  82.           ret
  83.  
  84. labl5:                            ; label successfully created
  85.           mov      dx,offset msg3 ; print first part message
  86.           mov      ah,9
  87.           int      21h
  88.           mov      bx,offset fcb+1 ; print actual volume name
  89.           call     print_vol       ; in upper case
  90.           ret                      ; exit to PC-DOS
  91. labl      endp
  92.  
  93.  
  94. show_label proc near               ; display the label for the
  95.                                    ; disk in the selected drive and
  96.                                    ; return AX=-1, or display message
  97.                                    ; and return AX = 0 if no label exists
  98.           mov      dx,offset buffer
  99.           mov      ah,26           ; set disk transfer address
  100.           int      21h             ; for use in directory search
  101.           mov      dx,offset sfcb  ; now look for the first directory
  102.                                    ; entry with volume attribute,
  103.           mov      ah,17           ; using PC-DOS function 17
  104.           int      21h             ; "search for first matching filename"
  105.           cmp      al,0ffh         ; any volume label found?
  106.           je       show_label2     ; no, jump
  107.           mov      dx,offset msg4  ; yes, print message and
  108.           mov      ah,9            ; volume name
  109.           int      21h
  110.           mov      bx,offset buffer+8
  111.           call     print_vol
  112.           mov      ax,-1           ; return AX = -1, label exists
  113.           ret
  114. show_label2:                       ; disk was not labeled,
  115.           mov      dx,offset msg5  ; so print message and return
  116.           mov      ah,9            ; return AX = 0 as signal that
  117.           int      21h             ; there is no previous label
  118.           xor      ax,ax
  119.           ret
  120. show_label endp
  121.  
  122.  
  123. print_vol proc     near            ; print the volume name
  124.                                    ; whose offset is in BX on
  125.                                    ; the standard output device.
  126.                                    ; Regs AX, BX & DX destroyed.
  127.           mov      cx,11           ; name is max of 11 characters
  128. pvol2:
  129.           mov      dl,[bx]         ; get next char from string
  130.           cmp      dl,' '
  131.           je       pvol4
  132.           cmp      dl,'a'          ; if it is in lowercase alpha
  133.           jb       pvol3           ; character, fold to uppercase
  134.           cmp      dl,'z'
  135.           ja       pvol3
  136.           xor      dl,20h
  137. pvol3:
  138.           mov      ah,2            ; funtion 2 = output char.
  139.           int      21h             ; request PC -DOS
  140. pvol4:    inc      bx              ; advance to next string position
  141.           loop     pvol2           ; until 11 chars. processed
  142. pvol9:                             ; done with string output
  143.           mov      dx,offset msg1  ; send final carriage return
  144.           mov      ah,9            ; and line feed
  145.           int      21h
  146.           ret                      ; then reutrn to caller
  147. print_vol endp
  148.  
  149. vol_name  proc near                ; Transfer the new volume name
  150.                                    ; from the Program Prefix Segment
  151.                                    ; into local File Control Block
  152.  
  153.                                    ; let DS:SI = command tail address
  154.           mov      si,offset command
  155.           lodsb                    ; check string length byte,
  156.           or       al,al           ; any name present?
  157.           jz       vol_name4       ; no, go get drive
  158. vol_name1:                         ; scan for start of name
  159.           lodsb                    ; get next char
  160.           cmp      al,cr           ; if carriage return, name is missing
  161.           je       vol_name4       ; so jump to get drive
  162.           cmp      al,' '          ; if blank, keep looking
  163.           je       vol_name1
  164.                                    ; now found non-blank character
  165.                                    ; let ES:DI = command tail address
  166.           mov      di,offset fcb+1 ; in local file control block
  167.           mov      cx,11           ; CX will be counter, 11 chars max.
  168.                                    ; did DOS parser find legal drive?
  169.           mov      ah,ds:default_fcb
  170.           or       ah,ah
  171.           jz       vol_name2       ; no, jump
  172.           lodsb                    ; yes, then next char ought to
  173.           cmp      al,':'          ; be a colon
  174.           jne      vol_name4       ; not colon, some kind of error.
  175.           lodsb                    ; fetch next character after colon
  176.           cmp      al,' '          ; make sure name is also there
  177.           jna      vol_name4       ; no name, jump to get drive.
  178. vol_name2:                         ; now we transfer bytes from
  179.                                    ; command tail to fcb
  180.                                    ; for the new volume name.
  181.           stosb
  182.           lodsb                    ; check next char from input
  183.           cmp      al,' '          ; if blank or any control char
  184.           jna      vol_name4       ; found end of name.
  185.           loop     vol_name2       ; otherwise, keep looking until
  186.                                    ; 11 characters have been processed.
  187. vol_name4:
  188.           mov      al,ds:default_fcb
  189.           or       al,al           ; was disk drive specified?
  190.           jnz      vol_name5       ; yes, use it.
  191.           mov      ah,25           ; no, get identity of default drive.
  192.           int      21h
  193.           inc      al
  194. vol_name5:                         ; put drive into file control blocks
  195.           mov      es:fcb,al       ; for search and new volume name.
  196.           mov      es:sfcb+7,al
  197.           add      al,'a'-1        ; also form ASCII letter for
  198.           mov      es:msg2a,al     ; drive, and put into
  199.           mov      es:msg3a,al     ; output messages.
  200.           mov      es:msg4a,al
  201.           mov      es:msg5a,al
  202.           ret
  203. vol_name  endp
  204.  
  205.           cseg     ends
  206.  
  207.                                    ; data segment for
  208.                                    ; miscellaneous messages,
  209.                                    ; constants, and variables
  210. data      segment para public 'DATA'
  211.                                    ; extended file control block
  212. xfcb      db       0ffh            ; flag for special fcb
  213.           db       5 dup(0)        ; reserved
  214.           db       volume          ; volume label attribute byte
  215.                                    ; remainder is "normal" fcb
  216. fcb       db       0               ; drive (set by VOL_NAME)
  217.           db       11 dup(' ')     ; blank name field
  218.           db       25 dup(0)
  219. sfcb      db       0ffh            ; extended file control block used
  220.           db       5 dup(0)        ; to search for current label
  221.           db       volume
  222.           db       0               ; drive (set by (VOL_NAME)
  223.           db       11 dup('?')     ; blank name field
  224.           db       25 dup(0)
  225. buffer    db       128 dup(?)      ; buffer for disk directory search
  226. msg1      db       cr,lf,eom
  227. msg2      db       cr,lf
  228.           db       'Unable to write new label on disk '
  229. msg2a     db       'x: ',cr,lf,eom
  230. msg3      db       cr,lf
  231.           db       'Label of disk in drive '
  232. msg3a     db       'x: has been changed to ',eom
  233. msg4      db       cr,lf,'Label of disk in drive '
  234. msg4a     db       'x: is ',eom
  235. msg5      db       cr,lf,'Disk in drive '
  236. msg5a     db       'x: has no label',cr,lf,eom
  237. msg6      db       cr,lf
  238.           db       'LABEL program requires DOS'
  239.           db       'version 2.0 or greater.'
  240.           db       cr,lf,eom
  241. data      ends
  242.  
  243.  
  244. stack     segment  para stack 'STACK'
  245.           db       64 dup(?)
  246. stack     ends
  247.  
  248.           end      labl
  249.  
  250.